//
//  AMTabbar.swift
//  微博
//
//  Created by zhc on 15/11/23.
//  Copyright © 2015年 zhc. All rights reserved.
//

import UIKit

class AMTabbar: UITabBar {
   
    
    
    override func layoutSubviews() {
        super.layoutSubviews()
    
    let width = bounds.size.width/5
    let frame = CGRect(x: 0, y: 0, width: width, height: bounds.size.height)
    //记录是第几个view
    var index = 0
        
        for view in self.subviews{
          
            if view is UIControl && !(view is UIButton){
                
                view.frame = CGRectOffset(frame, CGFloat(index)*width, 0)
                
                index+=index==1 ? 2 : 1
            
            }
      
        }
        
       compostButton.frame = CGRectOffset(frame, 2*width, 0)
 
    }
    
     //懒加载
    
    
    lazy var compostButton: UIButton = {
        
        let button = UIButton()
        
        //设置按钮背景图片
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        
        //设置按钮图片
        
        button.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        button.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        
        
       self.addSubview(button)
        
        return button
        
    }()
    
    
    
    
    

}
